<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/12/12
 * Time: 9:56
 */

class GetActiveDetail_model extends MY_Model
{
    function get_active_detail($id)
    {
        $table = 'ws_active_list';
        $where = array('id' => $id);
        $sql = /** @lang text */
            "SELECT COUNT(a.`id`) AS 'join',a.`id`,a.`title`,a.`share_total`,a.`look_total`,a.`data`,a.`type`,a.`start_date`,a.`active_date`, DATEDIFF(a.`start_date`,DATE_FORMAT(NOW(),'%Y-%m-%d')) AS start, DATEDIFF(a.`end_date`,DATE_FORMAT(NOW(),'%Y-%m-%d')) AS surplus FROM ws_active_list a LEFT JOIN ws_active_record b ON a.`id`=b.`aid` WHERE a.`id`= $id  GROUP BY a.`id`";

        $query = $this->db->query($sql);
        if ($query) {
            return $query->result_array();
        }
        return false;

//        $res = $this->my_select($table, $where, 'title,data,share_total,look_total');
//        $res_join = $this->my_select('ws_active_record', array('aid' => $id), 'count(*)');
//        $res[0]['join_total'] = $res_join;
//        return $res[0];
    }
}